package com.example.wjy.room;

import android.content.Context;

import com.example.room.dao.MasterDao;
import com.example.room.dao.TeamDao;
import com.example.room.entity.Master;
import com.example.room.entity.Team;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

/**
 * author: WangJunYan
 * package: com.example.wjy.room
 * date: 2020/6/19
 * time: 13:48
 * 本地数据库对象，采用单例模式，否则会消耗大量资源
 */
@Database(entities = {Team.class, Master.class},version = 1,exportSchema = false)
public abstract class NativeDatabase extends RoomDatabase {

    private static NativeDatabase INSTANCE;

    public static synchronized NativeDatabase getInstance(Context context) {
        if(INSTANCE == null) {
            INSTANCE = Room.databaseBuilder(context, NativeDatabase.class,"nativeDatabase")
            .build();
        }
        return INSTANCE;
    }

    public abstract TeamDao getTeamDao();
    public abstract MasterDao getMasterDao();
}
